package operation;

import book.book;
import book.bookList;

import java.awt.print.Book;
import java.util.Scanner;

public class BorrowBook implements IOperation{
    @Override
    public void work(bookList bookList) {
        System.out.println("借阅图书");
        System.out.println("请输入你要借阅的图书：");

        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        //先遍历数组查找是否存在要借阅的图书
        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            book book = bookList.getBook(i);
            if (book.getName().equals(name)){
                if (book.isBorrowed()){
                    System.out.println("这本书已经被借出了！ 无法借阅");
                }else{
                    book.setBorrowed(true);
                    System.out.println(book);
                    System.out.println("借阅成功....");
                }
                return;
            }
        }
        //2.如果不存在则不能借出

        //3.如果存在 检查是否已经被借出

        //4.如果没有借出可以借 否则不能借
        System.out.println("没有你要找的这本书 ， 无法借阅！");
    }
}
